package com.nbot.server.util;

import com.nbot.server.domain.RoleDO;
import com.nbot.server.domain.UserDO;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lovewinner on 2018/7/2.
 */
public class RoleUtil {
    public static List<RoleDO> getRoleDOs(UserDO userDO, List<RoleDO> roles) {
        boolean isAdmin = false;
        List<Long> roleIds = userDO.getRoleIds();
        for (Long rid : roleIds) {
            if (rid == 1) {
                isAdmin = true;
                break;
            }
        }
        List<RoleDO> hasRoles = new ArrayList<>();
        if (isAdmin) {
            hasRoles.addAll(roles);
        } else {
            for (RoleDO role : roles) {
                for (Long rid : roleIds) {
                    if (rid.equals(role.getRoleId())) {
                        hasRoles.add(role);
                    }
                }
            }
        }

        return hasRoles;
    }
}
